home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / inspector.jar / content / inspector / Flasher.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  5.1 KB  |  174 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Netscape Public License
  5.  * Version 1.1 (the "License"); you may not use this file except in
  6.  * compliance with the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/NPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is 
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Joe Hewitt <hewitt@netscape.com> (original author)
  23.  *
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. /***************************************************************
  40. * Flasher ---------------------------------------------------
  41. *   Object for controlling a timed flashing animation which 
  42. *   paints a border around an element.
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  44. * REQUIRED IMPORTS:
  45. ****************************************************************/
  46.  
  47. //////////// global variables /////////////////////
  48.  
  49. var gFlasherRegistry = [];
  50.  
  51. //////////// global constants ////////////////////
  52.  
  53. ////////////////////////////////////////////////////////////////////////////
  54. //// class Flasher
  55.  
  56. function Flasher(aColor, aThickness, aDuration, aSpeed, aInvert)
  57. {
  58.   this.mShell = XPCU.createInstance("@mozilla.org/inspector/flasher;1", "inIFlasher");;
  59.   this.color = aColor;
  60.   this.mThickness = aThickness;
  61.   this.duration = aDuration;
  62.   this.mSpeed = aSpeed;
  63.   this.mInvert = aInvert;
  64.   
  65.   this.register();
  66. }
  67.  
  68. Flasher.prototype = 
  69. {
  70.   ////////////////////////////////////////////////////////////////////////////
  71.   //// Initialization
  72.  
  73.   mFlashTimeout: null,
  74.   mElement:null,
  75.   mRegistryId: null,
  76.   mFlashes: 0,
  77.   mStartTime: 0,
  78.   mColor: null,
  79.   mThickness: 0,
  80.   mDuration: 0,
  81.   mSpeed: 0,
  82.   mInvert: false,
  83.  
  84.   ////////////////////////////////////////////////////////////////////////////
  85.   //// Properties
  86.  
  87.   get flashing() { return this.mFlashTimeout != null; },
  88.   
  89.   get element() { return this.mElement; },
  90.   set element(val) 
  91.   { 
  92.     if (val && val.nodeType == 1) {
  93.       this.mElement = val; 
  94.       if ("scrollIntoView" in val) {
  95.         val.scrollIntoView(false);
  96.       }
  97.     } else 
  98.       throw "Invalid node type.";
  99.   },
  100.  
  101.   get color() { return this.mColor; },
  102.   set color(aVal) { if (aVal.charAt(0) == '#') aVal = aVal.substr(1); this.mColor = aVal; },
  103.  
  104.   get thickness() { return this.mThickness; },
  105.   set thickness(aVal) { this.mThickness = aVal; },
  106.  
  107.   get duration() { return this.mDuration; },
  108.   set duration(aVal) { this.mDuration = aVal; },
  109.  
  110.   get speed() { return this.mSpeed; },
  111.   set speed(aVal) { this.mSpeed = aVal; },
  112.  
  113.   get invert() { return this.mInvert; },
  114.   set invert(aVal) { this.mInvert = aVal; },
  115.  
  116.   // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  117.   // :::::::::::::::::::: Methods ::::::::::::::::::::::::::::
  118.   // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  119.  
  120.   register: function()
  121.   {
  122.     var length = gFlasherRegistry.length;
  123.     gFlasherRegistry[length] = this;
  124.     this.mRegistryId = length;
  125.   },
  126.  
  127.   start: function(aDuration, aSpeed, aHold)
  128.   {
  129.     this.mUDuration = aDuration ? aDuration*1000 : this.mDuration;
  130.     this.mUSpeed = aSpeed ? aSpeed : this.mSpeed
  131.     this.mHold = aHold;
  132.     this.mFlashes = 0;
  133.     this.mStartTime = new Date();
  134.     this.doFlash();
  135.   },
  136.  
  137.   doFlash: function()
  138.   {
  139.     if (this.mHold || this.mFlashes%2) {
  140.       this.paintOn();
  141.     } else {
  142.       this.paintOff();
  143.     }
  144.     this.mFlashes++;
  145.  
  146.     if (this.mUDuration < 0 || new Date() - this.mStartTime < this.mUDuration) {
  147.       this.mFlashTimeout = window.setTimeout("gFlasherRegistry["+this.mRegistryId+"].doFlash()", this.mUSpeed);
  148.     } else {
  149.       this.stop();
  150.     }
  151. },
  152.  
  153.   stop: function()
  154.   {
  155.     if (this.flashing) {
  156.       window.clearTimeout(this.mFlashTimeout);
  157.       this.mFlashTimeout = null;
  158.       this.paintOff();
  159.     }
  160.   },
  161.  
  162.   paintOn: function()
  163.   {
  164.     this.mShell.drawElementOutline(this.mElement, this.mColor, this.mThickness, this.mInvert);
  165.   },
  166.  
  167.   paintOff: function()
  168.   {
  169.     this.mShell.repaintElement(this.mElement);
  170.   }
  171.  
  172. };
  173.  
  174.